// PursuitPhysics.cpp
//

#include "PursuitPhysics.h"

NxPhysicsSDK* PP_PhysxSDK;
NxScene* PP_PhysxScene;

PPHYSICS_API PDRESULT PPInitPhysics(PCSettings settings)
{
	NxSDKCreateError createerr;
	NxPhysicsSDKDesc sdkDesc;
	
	PP_PhysxSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, NULL, sdkDesc, &createerr);

	if (createerr != NXCE_NO_ERROR)
	{
		PCErrorNxSDKCreate(createerr, "Die PhysX-SDK konnte nicht initialisiert werden!");
		return PDERROR_PHYSXINIT;
	}

	NxSceneDesc sceneDesc;
	sceneDesc.gravity = NxVec3(0.0f, -9.81f, 0.0f);
	sceneDesc.groundPlane = true;
	sceneDesc.flags |= NX_SF_ENABLE_MULTITHREAD;

	PP_PhysxScene = PP_PhysxSDK->createScene(sceneDesc);

	if (PP_PhysxScene == NULL)
	{
		
		return PDERROR_PHYSXINIT;
	}

	return PD_OK;
}

PPHYSICS_API void PPReleasePhysics(void)
{
	if (PP_PhysxSDK != NULL)
	{
		if (PP_PhysxScene != NULL)
		{
			PP_PhysxSDK->releaseScene(*PP_PhysxScene);
		}
		PP_PhysxSDK->release();
	}
}